package org.cy.spring.learning.rpc.client;

import java.lang.reflect.Proxy;

/**
 * create date: 2019/10/18 12:16
 *
 * @author cao.yong
 */
@SuppressWarnings({"unchecked"})
public class ClientRemoteProxyFactory<T> {

    private Class<T> clazz;

    public ClientRemoteProxyFactory(Class<T> clazz) {
        this.clazz = clazz;
    }

    public T getRemoteService() {
        ClientRemoteInvokeHandler handler = new ClientRemoteInvokeHandler(clazz);
        return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, handler);
    }
}
